package xin.cms.model;

import lombok.Data;
import lombok.EqualsAndHashCode;
import xin.cms.enums.CheckStatus;
import xin.cms.enums.ArticleRorum;
import xin.core.jpa.JpaConstant;
import xin.core.jpa.model.AutoDateUUIDEntity;

import javax.persistence.*;
import java.util.List;

/**
 * <pre>
 * 文章
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2018/8/8
 */

@Entity
@Table(name = "cms_article")
@Data
@EqualsAndHashCode(callSuper = true)
public class Article extends AutoDateUUIDEntity {

    /**
     * 标题
     */
    @Column(length = JpaConstant.CommonStringMidLength)
    private String title;

    /**
     * 文章内容
     */
    @Column(columnDefinition = "longtext")
    private String content;

    /**
     * 作者
     */
    @Column(length = JpaConstant.NameColumnLength)
    private String author;

    /**
     * 板块
     * @see ArticleRorum
     */
    @Column(length = JpaConstant.EnumStringLargeColumnLength)
    private ArticleRorum forum;

    /**
     * 阅读次数
     */
    @Column
    private Integer readTimes;

    /**
     * 点赞次数
     */
    @Column
    private Integer likeTimes;

    /**
     * 踩次数
     */
    @Column
    private Integer unLikeTimes;

    /**
     * 来源
     */
    @Column(length = JpaConstant.CommonStringLargeLength)
    private String sourceInfo;

    /**
     * 来源地址
     */
    @Column(length = JpaConstant.CommonStringLargeLength)
    private String sourceUrl;

    /**
     * 置顶
     */
    @Column
    private Boolean isTop;

    /**
     * 状态
     * @see CheckStatus
     */
    @Column(length = JpaConstant.EnumStringShortColumnLength)
    private CheckStatus status;

    /**
     * 图片/轮播图
     */
    @Column(length = JpaConstant.CommonStringMidLength)
    private String sowingMap;


    /**
     * 是否开启评论
     */
    @Column
    private Boolean openComment;

    /**
     * 备注
     */
    @Column(length = JpaConstant.CommonStringLargeLength)
    private String remark;

    /**
     * 标签列表
     */
    @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE})
    @JoinTable(name = "cms_article_tag",
            joinColumns = {@JoinColumn(name = "article_id", nullable = false, updatable = false) },
            inverseJoinColumns = {@JoinColumn(name = "tag_id", nullable = false, updatable = false) })
    private List<Tag> tagList;
}
